using System;
using GameStateManagement;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;

namespace Life
{
    public class LoadScreen : SingleControlScreen
    {
        private InputAction pauseAction;
        private bool _mainMenuLaunch;

        public LoadScreen() : this(true) { }

        public LoadScreen(bool mainMenuLaunch)
        {
            _mainMenuLaunch = mainMenuLaunch;

            pauseAction = new InputAction(
                new Buttons[] { Buttons.Start, Buttons.Back },
                new Keys[] { Keys.Escape },
                true);
        }

        /// <summary>
        /// Load graphics content for the screen.
        /// </summary>
        public override void LoadContent()
        {
            EnabledGestures |= ScrollTracker.GesturesNeeded | GestureType.Tap | GestureType.Hold;
            RootControl = new LoadPanel(ScreenManager, true, 20);

            base.LoadContent();
        }

        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");


            PlayerIndex player;
            if (pauseAction.Evaluate(input, ControllingPlayer, out player))
            {
                if (_mainMenuLaunch)
                {
                    LoadingScreen.Load(ScreenManager, false, player, new BackgroundScreen(), new MainMenuScreen());
                }
                else
                {
                    LoadingScreen.Load(ScreenManager, false, player, new GameplayScreen());
                }
            }

            base.HandleInput(gameTime, input);
        }
    }
}
